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 
53  //FEDs and EBs
54  if ( feds_[0] != -1 ) {
55  edm::LogInfo("EcalPnGraphs") << "FED id is given! Goining to beginJob! ";
56  fedIsGiven = true;
57  }else {
58  feds_.clear();
59  if ( ebs_[0] !="none" ) {
60  //EB id is given and convert to FED id
61  fedMap = new EcalFedMap();
62  for (std::vector<std::string>::const_iterator ebItr = ebs_.begin();
63  ebItr!= ebs_.end(); ++ebItr) {
64  feds_.push_back(fedMap->getFedFromSlice(*ebItr));
65  }
66  delete fedMap;
67  } else {
68  //Select all FEDs in the Event
69  for ( int i=601; i<655; ++i){
70  feds_.push_back(i);
71  }
72  }
73  }
74 
75  // consistency checks checks
76  inputIsOk = true;
77  //check with FEDs
78  if ( fedIsGiven ) {
79  std::vector<int>::iterator fedIter;
80  for (fedIter = feds_.begin(); fedIter!=feds_.end(); ++fedIter) {
81  if ( (*fedIter) < 601 || (*fedIter) > 654) {
82  std::cout << "[EcalPnGraphs] pn number : " << (*fedIter) << " found in listFeds. "
83  << " Valid range is [601-654]. Returning." << std::endl;
84  inputIsOk = false;
85  return;
86  }
87  }
88  }
89 
90  //Check with Pns
91  if ( listPns[0] != -1 ) {
92  std::vector<int>::iterator intIter;
93  for (intIter = listPns.begin(); intIter != listPns.end(); intIter++) {
94  if ( ((*intIter) < 1) || (10 < (*intIter)) ) {
95  std::cout << "[EcalPnGraphs] pn number : " << (*intIter) << " found in listPns. "
96  << " Valid range is 1-10. Returning." << std::endl;
97  inputIsOk = false;
98  return;
99  }
100  if (!first_Pn ) first_Pn = (*intIter);
101  }
102  } else {
103  listPns.clear();
104  listPns.push_back(5);
105  listPns.push_back(6);
106  }
107 
108  // setting the abcissa array once for all
109  for (int i=0; i<50; i++) abscissa[i] = i;
110 
111  // local event counter (in general different from LV1)
112  eventCounter =0;
113 }
114 
115 
116 //=============================================================================
118 //=============================================================================
119  //delete *;
120 }
121 
122 //=============================================================================
124 //=============================================================================
125  edm::LogInfo("EcalPhGraphs") << "entering beginJob! " ;
126 }
127 
128 //=============================================================================
130 //=============================================================================
131 
132  eventCounter++;
133  if (!inputIsOk) return;
134 
135  // retrieving crystal PN diodes from Event
137  try {
138  e.getByLabel(digiProducer_, pn_digis);
139  } catch (cms::Exception& ex) {
140  edm::LogError("EcalPnGraphs") << "PNs were not found!";
141  }
142 
143  // getting the list of all the Pns which will be dumped on TGraph
144  // - listPns is the list as given by the user
145  // -numPn is the number of Pns (centered at Pn from listPns) for which graphs are required
146  std::vector<int>::iterator pn_it;
147  for ( pn_it = listPns.begin(); pn_it != listPns.end() ; pn_it++ )
148  {
149  int ipn = (*pn_it);
150  int hpn = numPn;
151 
152  for (int u = (-hpn) ; u<=hpn; u++){
153  int ipn_c = ipn + u;
154  if (ipn_c < 1 || ipn_c > 10) continue;
155  std::vector<int>::iterator notInList = find(listAllPns.begin(), listAllPns.end(), ipn_c);
156  if ( notInList == listAllPns.end() ) {
157  listAllPns.push_back ( ipn_c );
158  }
159  }
160  }
161 
162  //Loop over PN digis
163  for ( EcalPnDiodeDigiCollection::const_iterator pnItr = pn_digis->begin(); pnItr != pn_digis->end(); ++pnItr ) {
164  //Get PNid of a digi
165  int ipn = (*pnItr).id().iPnId();
166  //Get DCC id where the digi is from
167  int ieb = EcalPnDiodeDetId((*pnItr).id()).iDCCId();
168 
169  //Make sure that these are PnDigis from the requested FEDid
170  int FEDid = ieb + 600;
171 
172  std::vector<int>::iterator fedIter = find(feds_.begin(), feds_.end(), FEDid);
173 
174  if ( fedIter == feds_.end() ) {
175  edm::LogWarning("EcalPnGraphs")<< "For Event " << eventCounter << " PnDigis are not found from requested SM!. returning...";
176  return;
177  }
178  // selecting desired Pns only
179  std::vector<int>::iterator iPnIter;
180  iPnIter = find( listAllPns.begin() , listAllPns.end() , ipn);
181  if (iPnIter == listAllPns.end()) continue;
182 
183  for ( int i=0; i< (*pnItr).size() && i<50; ++i ) {
184  ordinate[i] = (*pnItr).sample(i).adc();
185  }
186  //make grapn of ph digis
187  TGraph oneGraph(50, abscissa,ordinate);
188  std::string title;
189  title = "Graph_ev" + intToString( eventCounter )
190  + "_FED" + intToString( FEDid )
191  + "_ipn" + intToString( ipn );
192  oneGraph.SetTitle(title.c_str());
193  oneGraph.SetName(title.c_str());
194  graphs.push_back(oneGraph);
195 
196  }// loop over Pn digis
197 }
198 
200 {
201  //
202  // outputs the number into the string stream and then flushes
203  // the buffer (makes sure the output is put into the stream)
204  //
205  std::ostringstream myStream; //creates an ostringstream object
206  myStream << num << std::flush;
207 
208  return(myStream.str()); //returns the string form of the stringstream object
209 }
210 
211 //=============================================================================
213 //=============================================================================
214  fileName += ( std::string("_Pn") + intToString(first_Pn) );
215  fileName += ".graph.root";
216 
217  root_file = new TFile( fileName.c_str() , "RECREATE" );
218  std::vector<TGraph>::iterator gr_it;
219  for ( gr_it = graphs.begin(); gr_it != graphs.end(); gr_it++ ) (*gr_it).Write();
220  root_file->Close();
221 
222  edm::LogInfo("EcalPnGraphs") << "DONE!.... " ;
223 }
224 
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:356
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:121
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)