CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalPnGraphs.cc
Go to the documentation of this file.
1 
17 
20 
23 
24 #include <iostream>
25 #include <vector>
26 #include <map>
27 
28 #include "TFile.h"
29 #include "TGraph.h"
30 
31 
32 //=============================================================================
34 //=============================================================================
35 
36  digiProducer_ = ps.getParameter<std::string>("digiProducer");
37  fileName = ps.getUntrackedParameter<std::string >("fileName", std::string("toto") );
38 
39  first_Pn = 0;
40 
41  listPns = ps.getUntrackedParameter<std::vector<int> >("listPns", std::vector<int>());
42  numPn = ps.getUntrackedParameter< int >("numPn");
43 
44  std::vector<int> listDefaults;
45  listDefaults.push_back(-1);
46  feds_ = ps.getUntrackedParameter<std::vector<int> > ("requestedFeds",listDefaults);
47  bool fedIsGiven = false;
48 
49  std::vector<std::string> ebDefaults;
50  ebDefaults.push_back("none");
51  ebs_ = ps.getUntrackedParameter<std::vector<std::string> >("requestedEbs",ebDefaults);
52  bool ebIsGiven = false;
53 
54  //FEDs and EBs
55  if ( feds_[0] != -1 ) {
56  edm::LogInfo("EcalPnGraphs") << "FED id is given! Goining to beginJob! ";
57  fedIsGiven = true;
58  }else {
59  feds_.clear();
60  if ( ebs_[0] !="none" ) {
61  ebIsGiven = true;
62  //EB id is given and convert to FED id
63  fedMap = new EcalFedMap();
64  for (std::vector<std::string>::const_iterator ebItr = ebs_.begin();
65  ebItr!= ebs_.end(); ++ebItr) {
66  feds_.push_back(fedMap->getFedFromSlice(*ebItr));
67  }
68  delete fedMap;
69  } else {
70  //Select all FEDs in the Event
71  for ( int i=601; i<655; ++i){
72  feds_.push_back(i);
73  }
74  }
75  }
76 
77  // consistency checks checks
78  inputIsOk = true;
79  //check with FEDs
80  if ( fedIsGiven ) {
81  std::vector<int>::iterator fedIter;
82  for (fedIter = feds_.begin(); fedIter!=feds_.end(); ++fedIter) {
83  if ( (*fedIter) < 601 || (*fedIter) > 654) {
84  std::cout << "[EcalPnGraphs] pn number : " << (*fedIter) << " found in listFeds. "
85  << " Valid range is [601-654]. Returning." << std::endl;
86  inputIsOk = false;
87  return;
88  }
89  }
90  }
91 
92  //Check with Pns
93  if ( listPns[0] != -1 ) {
94  std::vector<int>::iterator intIter;
95  for (intIter = listPns.begin(); intIter != listPns.end(); intIter++) {
96  if ( ((*intIter) < 1) || (10 < (*intIter)) ) {
97  std::cout << "[EcalPnGraphs] pn number : " << (*intIter) << " found in listPns. "
98  << " Valid range is 1-10. Returning." << std::endl;
99  inputIsOk = false;
100  return;
101  }
102  if (!first_Pn ) first_Pn = (*intIter);
103  }
104  } else {
105  listPns.clear();
106  listPns.push_back(5);
107  listPns.push_back(6);
108  }
109 
110  // setting the abcissa array once for all
111  for (int i=0; i<50; i++) abscissa[i] = i;
112 
113  // local event counter (in general different from LV1)
114  eventCounter =0;
115 }
116 
117 
118 //=============================================================================
120 //=============================================================================
121  //delete *;
122 }
123 
124 //=============================================================================
126 //=============================================================================
127  edm::LogInfo("EcalPhGraphs") << "entering beginJob! " ;
128 }
129 
130 //=============================================================================
132 //=============================================================================
133 
134  eventCounter++;
135  if (!inputIsOk) return;
136 
137  bool pnDigisFound = true;
138  // retrieving crystal PN diodes from Event
140  try {
141  e.getByLabel(digiProducer_, pn_digis);
142  pnDigisFound = true;
143  } catch (cms::Exception& ex) {
144  edm::LogError("EcalPnGraphs") << "PNs were not found!";
145  }
146 
147  // getting the list of all the Pns which will be dumped on TGraph
148  // - listPns is the list as given by the user
149  // -numPn is the number of Pns (centered at Pn from listPns) for which graphs are required
150  std::vector<int>::iterator pn_it;
151  for ( pn_it = listPns.begin(); pn_it != listPns.end() ; pn_it++ )
152  {
153  int ipn = (*pn_it);
154  int hpn = numPn;
155 
156  for (int u = (-hpn) ; u<=hpn; u++){
157  int ipn_c = ipn + u;
158  if (ipn_c < 1 || ipn_c > 10) continue;
159  std::vector<int>::iterator notInList = find(listAllPns.begin(), listAllPns.end(), ipn_c);
160  if ( notInList == listAllPns.end() ) {
161  listAllPns.push_back ( ipn_c );
162  }
163  }
164  }
165 
166  //Loop over PN digis
167  for ( EcalPnDiodeDigiCollection::const_iterator pnItr = pn_digis->begin(); pnItr != pn_digis->end(); ++pnItr ) {
168  //Get PNid of a digi
169  int ipn = (*pnItr).id().iPnId();
170  //Get DCC id where the digi is from
171  int ieb = EcalPnDiodeDetId((*pnItr).id()).iDCCId();
172 
173  //Make sure that these are PnDigis from the requested FEDid
174  int FEDid = ieb + 600;
175 
176  std::vector<int>::iterator fedIter = find(feds_.begin(), feds_.end(), FEDid);
177 
178  if ( fedIter == feds_.end() ) {
179  edm::LogWarning("EcalPnGraphs")<< "For Event " << eventCounter << " PnDigis are not found from requested SM!. returning...";
180  return;
181  }
182  // selecting desired Pns only
183  std::vector<int>::iterator iPnIter;
184  iPnIter = find( listAllPns.begin() , listAllPns.end() , ipn);
185  if (iPnIter == listAllPns.end()) continue;
186 
187  for ( int i=0; i< (*pnItr).size() && i<50; ++i ) {
188  ordinate[i] = (*pnItr).sample(i).adc();
189  }
190  //make grapn of ph digis
191  TGraph oneGraph(50, abscissa,ordinate);
192  std::string title;
193  title = "Graph_ev" + intToString( eventCounter )
194  + "_FED" + intToString( FEDid )
195  + "_ipn" + intToString( ipn );
196  oneGraph.SetTitle(title.c_str());
197  oneGraph.SetName(title.c_str());
198  graphs.push_back(oneGraph);
199 
200  }// loop over Pn digis
201 }
202 
204 {
205  //
206  // outputs the number into the string stream and then flushes
207  // the buffer (makes sure the output is put into the stream)
208  //
209  std::ostringstream myStream; //creates an ostringstream object
210  myStream << num << std::flush;
211 
212  return(myStream.str()); //returns the string form of the stringstream object
213 }
214 
215 //=============================================================================
217 //=============================================================================
218  fileName += ( std::string("_Pn") + intToString(first_Pn) );
219  fileName += ".graph.root";
220 
221  root_file = new TFile( fileName.c_str() , "RECREATE" );
222  std::vector<TGraph>::iterator gr_it;
223  for ( gr_it = graphs.begin(); gr_it != graphs.end(); gr_it++ ) (*gr_it).Write();
224  root_file->Close();
225 
226  edm::LogInfo("EcalPnGraphs") << "DONE!.... " ;
227 }
228 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
int abscissa[50]
Definition: EcalPnGraphs.h:67
virtual void endJob()
int getFedFromSlice(std::string)
Definition: EcalFedMap.cc:104
std::vector< T >::const_iterator const_iterator
std::string intToString(int num)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< int > feds_
Definition: EcalPnGraphs.h:46
virtual void beginJob()
std::string fileName
Definition: EcalPnGraphs.h:58
EcalFedMap * fedMap
Definition: EcalPnGraphs.h:38
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
std::vector< TGraph > graphs
Definition: EcalPnGraphs.h:70
int ordinate[50]
Definition: EcalPnGraphs.h:68
std::string digiProducer_
Definition: EcalPnGraphs.h:44
std::vector< int > listAllPns
Definition: EcalPnGraphs.h:63
long long int num
Definition: procUtils.cc:71
std::vector< std::string > ebs_
Definition: EcalPnGraphs.h:47
std::vector< int > listPns
Definition: EcalPnGraphs.h:62
tuple cout
Definition: gather_cfg.py:41
TFile * root_file
Definition: EcalPnGraphs.h:72
EcalPnGraphs(const edm::ParameterSet &ps)
Definition: EcalPnGraphs.cc:33
virtual void analyze(const edm::Event &e, const edm::EventSetup &c)